<template>
  <div class="pos_salary_chart">
    <highcharts :options="posSalarychartOptions"></highcharts>
  </div>
</template>

<script>
import { requestPositionSalaryChart } from "@/api/index.js";

export default {
  name: "PositionSalaryChart",
  props: ["positionSalary"],
  data() {
    this.getData();
    return {
      posSalarychartOptions: {
        chart: {
          borderWidth: 0.5,
          borderColor: "#000",
          type: "column"
        },
        title: {
          text: "职位薪资统计"
        },
        subtitle: {
          text: "数据来源：redas"
        },
        xAxis: {
          title:{
            text: "薪资区间"
          },
          categories:[]
        },
        yAxis: {
          title: {
            text: "职位数量"
          }
        },
        // 版权水印
        credits: {
          // enabled: false,
          text: "redas",
          href: "#"
        },
        series: [
          {
            name: "data",
            data: []
          }
        ]
      }
    };
  },
  methods: {
    getData: function() {
      let vue = this;
      let send_data = {
        position: vue.positionSalary.position,
        edu: vue.positionSalary.education,
        exp: vue.positionSalary.experience,
        city: vue.positionSalary.city,
        startDate: vue.positionSalary.startDate,
        endDate: vue.positionSalary.endDate
      };

      requestPositionSalaryChart(send_data).then(data => {
        let c = vue.posSalarychartOptions.xAxis.categories;
        let d = vue.posSalarychartOptions.series[0].data;
        // 清空数组
        c.splice(0,c.length);
        d.splice(0,d.length);

        for(let i = 0;i<data.result.length;i++){
            c.push(data.result[i].x);
            d.push(data.result[i].y);
        }
        
      });
    }
  },
  watch: {
    positionSalary: function(new_data, old_data) {
      if (new_data != "") {
        this.getData();
      }
    }
  }
};
</script>

<style>
.pos_salary_chart {
  margin-top: 20px;
}
</style>
